package com.fairytask.ui.item
{
	import com.fairytask.engine.components.BaseItem;
	import com.fairytask.engine.components.ToolTips;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.group.ViewGroup;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.resource.StaticIni;
	import com.jzonl.managers.TipsManage;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * 战斗结果对象 
	 * @author xujh
	 * 
	 */
	public class ResultItem extends Sprite
	{
		//========================================
		private var _bgMc		:Clip = new Clip();
		private var _getVg		:ViewGroup;
//		private var resultSP	:Sprite = new Sprite();
		private var _expMc		:Clip = new Clip();
		private var _sptMc		:Clip = new Clip();
		private var _silMc		:Clip = new Clip();
		private var _itemMc	:Clip = new Clip();		//掉落物品
		
		private var batNum		:Label = new Label("FFFFFF");	//第XX次胜利
		private var expLab		:Label = new Label("00FF00");	//经验
		private var sptLab		:Label = new Label("00FF00");	//灵
		private var silLab		:Label = new Label("00FF00");	//银两
		
		//输赢文字，临时写字
		private var winMc		:Label =new Label("FF0000",18);
		
		private var _result	:Boolean;//1赢0输
		
		public function ResultItem()
		{
			init();
			initEvent();
		}
		
		/**
		 * 初始化设置 
		 * 
		 */
		private function init():void
		{
			//背景
			_bgMc.source =  ResConfig.uiBGPath + "offline_result.png";
			addChild(_bgMc);
			
			//固定文字图片初始化
			_expMc.source = ResConfig.uiBGPath + "exp_en.png";
			_expMc.x = 0;
			_expMc.y = 40;
			addChild(_expMc);
			
			_sptMc.source = ResConfig.uiBGPath + "spirit.png";
			_sptMc.x = 190;
			_sptMc.y = 39;
			addChild(_sptMc);
			
			_silMc.source = ResConfig.uiBGPath + "silver.png";
			_silMc.x = 100;
			_silMc.y = 39;
			addChild(_silMc);
			
			//文字初始化
			batNum.x = 240;
			batNum.y = 10;
			addChild(batNum);
			
			expLab.x = 35;
			expLab.y = 38;
			addChild(expLab);
			
			sptLab.x = 220;
			sptLab.y = 38;
			addChild(sptLab);
			
			silLab.x = 135;
			silLab.y = 38;
			addChild(silLab);
			
			_itemMc.source = ResConfig.uiBGPath + "item.png";
			_itemMc.x = 0;
			_itemMc.y = 60;
			addChild(_itemMc);
			
			//物品列表初始化
			_getVg = new ViewGroup(1,5,"CustSkin_017",56,56);
			_getVg.offsetCol = 5;
			for(var i:int=0;i<5;i++)
			{
				var tmpItem		:BagItemBak		=	new BagItemBak();
				var baseItem	:BaseItem	=	_getVg.getItemByIndex(i);
				baseItem.addItem(tmpItem);
			}
			_getVg.y = 85;
			addChild(_getVg);
			
//			addChild(resultSP);
			//初始化文字,临时
			winMc.htmlStrByBorder = "战斗胜利！";
			winMc.x = 5;
			winMc.y = 5;
			addChild(winMc);
		}
		
		private function initEvent():void
		{
			
		}
		
		/**
		 * 获取物品列表 
		 * @param val
		 * 
		 */
		public function set cfgList(val:Array):void
		{
			
		}
		
		/**
		 * 获得经验 
		 * @param val
		 * 
		 */
		public function set getExp(val:int):void
		{
			expLab.htmlStrByBorder = String(val);
		}
		
		/**
		 * 获得灵 
		 * @param val
		 * 
		 */
		public function set getSpt(val:int):void
		{
			sptLab.htmlStrByBorder = String(val);
		}
		
		/**
		 * 获得银两
		 * @param val
		 * 
		 */
		public function set getSilver(val:int):void
		{
			silLab.htmlStrByBorder = String(val);
		}
		
		/**
		 * 战斗次数 
		 * @param val
		 * 
		 */
		public function set resultNum(val:int):void
		{
			batNum.htmlStrByBorder = "第"+val+"次胜利";
		}
		
		/**
		 * 获取物品 
		 * @param id
		 * @param num
		 * 
		 */
		public function getItem(pos:int,id:int,num:int):void
		{
			var tmpItem		:BagItemBak		=	new BagItemBak();
			var baseItem	:BaseItem	=	_getVg.getItemByIndex(pos);
//			tmpItem.source = ResConfig.iconPath + StaticIni.getIniVar(id,"Icon") + ResConfig.iconImg;
			tmpItem.configID = id;
			tmpItem.x = -1;
			tmpItem.y = -1;
			baseItem.addItem(tmpItem);
			tmpItem.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			tmpItem.addEventListener(MouseEvent.MOUSE_OUT,onOut);
			if(num > 1)
			{
				tmpItem.itemNum = num;
			}
		}
		
		/**
		 * 显示tips 
		 * @param evt
		 * 
		 */
		private function onOver(evt:MouseEvent):void
		{
			if(null!=evt.currentTarget)
			{
				TipsManage.ShowItemTips(uint(evt.currentTarget.configID));
			}
		}
		
		private function onOut(evt:MouseEvent):void
		{
			ToolTips.hide();
		}
		
		/**
		 * 设置战斗结果，1赢0输(只有赢)
		 * @param val
		 * 
		 */
		public function set resultVal(val:Boolean):void
		{
			_result	=	val;
			/*if(resultSP.numChildren>0)
			{
				resultSP.removeChildAt(0);
			}
			if(_result)
			{
				resultSP.addChild(winMc);
			}
			else
			{
				resultSP.addChild(loseMc);
			}*/
		}
	}
}